package com.tz.platform.tag.common;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * 平台封装标签，下拉列表通用标签
 * @version 4.0
 */
@SuppressWarnings("serial")
public abstract class SelectCommonTag extends TagSupport {
	
	private String id;
	private String name;
	private String value;
	private String defaultValue;
	private String cssClass;
	private String cssStyle;
	private String emptyOptionName;
	private String onChange;


	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public String getCssClass() {
		return cssClass;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public String getCssStyle() {
		return cssStyle;
	}

	public void setCssStyle(String cssStyle) {
		this.cssStyle = cssStyle;
	}

	public String getEmptyOptionName() {
		return emptyOptionName;
	}

	public void setEmptyOptionName(String emptyOptionName) {
		this.emptyOptionName = emptyOptionName;
	}

	public String getOnChange() {
		return onChange;
	}

	public void setOnChange(String onChange) {
		this.onChange = onChange;
	}

	@Override
	public int doStartTag() throws JspException {
		StringBuffer strOut = new StringBuffer();
		if (getId() == null || getId().equals("")) {
			setId(getName());
		}
		strOut.append("<select id=\"" + getId() + "\" name=\"" + getName() + "\"");
		if (getCssClass() != null && !getCssClass().equals("")) {
			strOut.append(" class=\"" + getCssClass() + "\"");
		}
		if (getOnChange() != null && !getOnChange().equals("")) {
			strOut.append(" onChange=\"" + getOnChange() + "\"");
		}
		strOut.append("\"");
		if (getCssStyle() != null && !getCssStyle().equals("")) {
			strOut.append(" style=\"" + getCssStyle() + "\"");
		}
		strOut.append(">");
		strOut.append(getSelectOption());
		strOut.append("</select>");
		try {
			pageContext.getOut().write(strOut.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}

	public abstract String getSelectOption();
}